public class Solution {
        public int totalFruit(int[] fruits) {
            //模拟hash表
            int[] hash = new int[fruits.length + 1];
            int ret = 0;//长度
            for(int left = 0,right = 0,kinds = 0;right < fruits.length; right++){
                //判断种类
                if(hash[fruits[right]] == 0) kinds++;
                //入窗口
                hash[fruits[right]]++;
                //判断
                while(kinds > 2){
                    //出窗口
                    hash[fruits[left]]--;
                    if(hash[fruits[left]] == 0){
                        kinds--;
                    }
                    left++;
                }
                //更新
                ret = Math.max(ret,right - left + 1);
            }
            return ret;
        }
    }

